#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time         : 17-12-6 上午8:58
# @Author       : xiaohan
# @File         : bisect_demo.py
# @desc         : 


import bisect
import sys

HAYSTACK = [1, 4, 5, 6, 8, 12, 15, 20, 21, 23, 23, 26, 29, 30]
NEEDLES = [0, 1, 2, 5, 8, 10, 22, 23, 29, 30, 31]
ROW_FMT = '{0:2d} @ {1:2d} {2}{0:<2d}'


def demo(bisect_fn):
    for needle in reversed(NEEDLES):
        positon = bisect_fn(HAYSTACK, needle)
        offset = positon * ' |'
        print(ROW_FMT.format(needle, positon, offset))


if __name__ == '__main__':
    bisect_fn = bisect.bisect_left
    demo(bisect_fn)
    print(HAYSTACK)